package com.lyf.scm.plan.api.controller;

import com.lyf.scm.common.model.ExcelExportDataDTO;
import com.lyf.scm.common.util.ExcelExportUtil;
import com.lyf.scm.plan.api.dto.DirectlyExecuteDTO;
import com.lyf.scm.plan.domain.service.DirectlyExecuteService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * description:
 *          直营预测计划--执行
 * @author: haodong
 * @data: 2020/8/5 13:29
 */
@Slf4j
@Api(tags = "直营预测计划--执行")
@RequestMapping("/api/v1/salesPlanDirectlyExecute")
@RomeController
public class DirectlyExecuteController {

    @Resource
    private DirectlyExecuteService directlyExecuteService;

    @PostMapping("/list")
    @ApiOperation(value = "按条件查询直营预测计划(天维度)")
    public Response listBySelective(@RequestBody DirectlyExecuteDTO salesPlanDirectlyExecute) {
        return Response.builderSuccess(directlyExecuteService.listBySelective(salesPlanDirectlyExecute));
    }

    @PostMapping("/listAll")
    @ApiOperation(value = "查询全渠道直营预测计划(天维度)")
    public Response listAllByDays(@RequestBody DirectlyExecuteDTO salesPlanDirectlyExecute) {
        return Response.builderSuccess(directlyExecuteService.listAllByDays(salesPlanDirectlyExecute));
    }

    @PostMapping("/export")
    @ApiOperation(value = "导出")
    public void exportExcel(@RequestBody DirectlyExecuteDTO salesPlanDirectly, @RequestParam("type") Integer type, HttpServletResponse httpServletResponse) {
        try {
            ExcelExportDataDTO excelExportDataDTO = directlyExecuteService.exportExcel(salesPlanDirectly, type);
            ExcelExportUtil.exportExcelDirectlyExecute(httpServletResponse, excelExportDataDTO);
        } catch (Exception e) {
            ExcelExportUtil.handleExceptionResponse(httpServletResponse, e);
        }
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除对应标识数据")
    public Response delete(@RequestParam("opSign") String opSign) {
        directlyExecuteService.delete(opSign);
        return Response.builderSuccess(null);
    }
}
